<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Hello Backbone.js</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../../libs/bootstrap/4.0.0-beta.3/bootstrap.min.css">
    <script src="../../../libs/jquery/3.2.1/jquery.js"></script>
    <script src="../../../libs/propper.js/1.13.0/umd/popper.js"></script>
    <script src="../../../libs/bootstrap/4.0.0-beta.3/bootstrap.min.js"></script>
    <script src="../../../libs/underscore.js/1.8.3/underscore.js"></script>
    <script src="../../../libs/backbone.js/1.3.3/backbone.js"></script>
    <style>
        #main-view {
            background: #3b76c0;
        }

        .pageview {
            height: 400px;
        }
    </style>
</head>

<body>
    <div id='app'>
            <button id="check">新手报到</button>
            <ul id="world-list">
            </ul>
    </div>
</body>

<script>
    (function ($) {
        World = Backbone.Model.extend({
            name: null
        });
        Worlds = Backbone.Collection.extend({
            initialize: function (model, options) {
                this.bind('add', options.view.addOneWorld);
            }
        });
        AppView = Backbone.View.extend({
            el: '#app',
            initialize: function () {
                this.worlds = new Worlds(null, {view: this});
            },
            events: {
                'click #check': 'checkIn',
            },
            checkIn: function () {
                var world_name = prompt('请问, 您是哪里人?');
                if (world_name == '') world_name = '未知';
                var world = new World({ name: world_name });
                this.worlds.add(world);
            },
            addOneWorld: function (model) {
                $("#world-list").append("<li>这里是来自 <b>" + model.get('name')
                    + "</b> 星球的问候：hello world！</li>");
            }
        });
        //实例化 AppView
        var appview = new AppView;
    })(jQuery);
</script>

</html>